const fp = require('lodash/fp')
const cars =[
    {name:'AAA',horsepower:660,dollar_value:82000,in_stcok:false},
    {name:'BBB',horsepower:720,dollar_value:32000,in_stcok:false},
    {name:'CCC',horsepower:650,dollar_value:58600,in_stcok:false},
    {name:'DDD',horsepower:660,dollar_value:69000,in_stcok:true},
    {name:'EEE',horsepower:560,dollar_value:62000,in_stcok:false},
]

//1.获取最后一数据的in_stcok
console.log('-------------1-------------');
const lastStcok = fp.flowRight(fp.prop('in_stcok'),fp.last)
console.log(lastStcok(cars));

//2.获取第一个汽车的name
console.log('-------------2-------------');
const firstName = fp.flowRight(fp.prop('name'),fp.first)
console.log(firstName(cars));

 //3.重构函数
 console.log('-------------3-------------');
 let _average = function(xs){
     return fp.reduce(fp.add, 0, xs) / xs.length
 }
const averageDollarValue = fp.flowRight(_average,fp.map(fp.prop('dollar_value')))
console.log(averageDollarValue(cars));

//4.转化字符串
console.log('-------------4-------------');
let _underscore = fp.replace(/\W+/g,'_')
const sanitizeNames = fp.flowRight(fp.split(' '),_underscore,fp.toLower)
console.log(sanitizeNames(["Hello World"]));

